// API 基础URL
const BASE_URL = 'http://localhost:8091/api/v1/monitor';

// API请求类
const MonitorAPI = {
    // 查询监控流程图
    queryMonitorFlowMap: async (monitorId) => {
        try {
            const response = await fetch(`${BASE_URL}/query_monitor_flow_map?monitorId=${monitorId}`);
            const data = await response.json();
            if (data.code === "0000") {
                return data.data;
            } else {
                throw new Error(data.info);
            }
        } catch (error) {
            console.error('Error loading flow map:', error);
            throw error;
        }
    },

    // 查询监控场景列表
    queryMonitorSceneList: async () => {
        try {
            const response = await fetch(`${BASE_URL}/query_monitor_data_map_entity_list`);
            const data = await response.json();
            if (data.code === "0000") {
                return data.data;
            } else {
                throw new Error(data.info);
            }
        } catch (error) {
            console.error('Error loading scene list:', error);
            throw error;
        }
    },

    // 查询监控数据列表
    queryMonitorDataList: async (monitorId, monitorName = '', monitorNodeId = '') => {
        try {
            const response = await fetch(
                `${BASE_URL}/query_monitor_data_list?monitorId=${monitorId}&monitorName=${monitorName}&monitorNodeId=${monitorNodeId}`
            );
            const data = await response.json();
            if (data.code === "0000") {
                return data.data;
            } else {
                throw new Error(data.info);
            }
        } catch (error) {
            console.error('Error loading monitor data:', error);
            throw error;
        }
    },

    // 更新监控流程设计
    updateMonitorFlowDesigner: async (monitorId, flowData) => {
        try {
            const response = await fetch(`${BASE_URL}/update_monitor_flow_designer?monitorId=${monitorId}`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: flowData
            });
            const data = await response.json();
            if (data.code === "0000") {
                return data;
            } else {
                throw new Error(data.info);
            }
        } catch (error) {
            console.error('Error updating flow designer:', error);
            throw error;
        }
    }
}; 